package yl.hs.bmipfull.controllers.salemanage;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.salemanage.IProductPricesService;
import yl.hs.bmipfull.service.system.ISearchViewService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * 作用:  产品信息价控制层<br/>
 * 创建时间: 2021年06月08日 09时27分20秒 <br/>
 *
 * @author 张凯
 */
@Api(value = "产品信息价Web接口", tags = "销售管理——产品信息价操作")
@RequestMapping(value = "/api/product")
@RestController
public class ProductPricesController extends ControllerBase {

    @Autowired
    IProductPricesService service;
    @Autowired
    ISearchViewService svSVC;

    @ApiOperation(value = "查询产品信息价", notes = "查询产品信息价")
    @RequestMapping(value = "prices", method = RequestMethod.POST)
    public WebResult queryList(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery) {
        try {
            return success("查询成功", service.queryList(pageQuery));
        } catch (Exception e) {
            return error(e);
        }
    }

    @ApiOperation(value = "查询产品信息价", notes = "分页查询产品信息价")
    @RequestMapping(value = "prices/{rowNum}/{page}", method = RequestMethod.POST)
    public WebResult queryPage(@RequestBody PageQuery query,
                               @ApiParam(value = "页码") @PathVariable int page,
                               @ApiParam(value = "每页条数") @PathVariable int rowNum) {
        try {

            var result = service.queryPage(query, rowNum, page);
            svSVC.updateUserMenuView(query);
            return success("ok", result);
        } catch (Exception ee) {
            return error(ee);
        }
    }




    @ApiOperation(value = "查询产品信息价", notes = "根据产品信息价编号查询产品信息价")
    @RequestMapping(value = "prices/{sn}", method = RequestMethod.GET)
    public WebResult findBySn(@ApiParam(value = "编号") @PathVariable String sn) {
        return success("查询成功", service.findBySn(sn));
    }
    @ApiOperation(value = "查询产品信息价", notes = "根据产品信息价编号查询产品信息价")
    @RequestMapping(value = "prices/{sn}", method = RequestMethod.DELETE)
    public WebResult delete(@ApiParam(value = "编号") @PathVariable String sn) {
        return success("删除成功", service.deleteBySN(sn));
    }


    @ApiOperation(value = "保存产品信息价", notes = "查询/更新产品信息价信息")
    @RequestMapping(value = "prices", method = RequestMethod.PUT)
    public WebResult saveMenu(@ApiParam(value = "提交信息") @RequestBody SubmitModel submitModel) {
        Integer result;
        try {
            result = service.saveProductPrices(submitModel.getData(), submitModel.getSn());
            if (result > 0) {
                return success("保存成功");
            } else {
                return fail("数据未保存");
            }
        } catch (Exception e) {
            return error(e);
        }

    }

    @ApiOperation(value = "查询产品信息价", notes = "根据产品信息价编号查询产品信息价")
    @RequestMapping(value = "product_prices/{productSN}", method = RequestMethod.GET)
    public WebResult findProductPriceBySn(@ApiParam(value = "编号") @PathVariable String productSN) {
        return success("查询成功", service.findProductPriceBySn(productSN));
    }

    @ApiOperation(value = "获取产品信息价设置时间分组信息", notes = "获取产品信息价设置时间 分组信息")
    @GetMapping("/prices/set-time-group")
    public WebResult getSetTimeGroup(){
        return success("ok", service.getSetTimeGroup());
    }


}